<template>
  <div class="app-container calendar-list-container">
    <search :list="queryList" :queryEntity="queryEntity"></search>
    <buttons :showQuery="true" :showBack="false" @query="doQuery" :list="btnList" :disabled="disabled" placeholder="订单号" :permissions="permissions" @delete="doDelete">
    </buttons>
    <grid gridTitle="扣款单" :url="url" :columns="columns" :enableEdit="false" :loading="true" ref="mainGrid" height="auto" diffHeight="125" :pagination="true"
      :permissions="permissions" :multi="false" @change="rowCilck" :queryEntity="queryEntity" @delete="doDelete">
    </grid>
  </div>
</template>
<script>
import request from '@/router/axios'
import { Message, MessageBox } from 'element-ui'
import url from '@/const/apiURL'
import grid from '@/components/Grid'
import buttons from '@/components/Buttons'
import { mapGetters } from 'vuex'
import { BusinessOrderStatusFormatter, BusinessTypeFormatter } from '@/const/dict'
import search from '@/components/Search'
import { colunms } from '@/const/colunms'
import { dict } from '@/const/dict'
import { queryField } from '@/const/query'

export default {
  components: { grid, buttons, search },
  data () {
    return {
      orderNo: '',
      url: url.DUDECTION_LIST_URL,
      entity: {},
      queryEntity: { key: 'key' },
      disabled: true,
      columns: [
        {
          label: '操作', width: 80, prop: 'op', align: 'center', template: 'op', opList: [
            { name: '删除', clickName: 'delete', auth: 'deduction_delete', confirm: true }
          ]
        },
        { label: '订单编号', width: 180, prop: 'orderNo', align: 'left' },
        { label: '加工单号', width: 180, prop: 'businessCode', align: 'left' },
        { label: '扣款单号', width: 180, prop: 'deductionCode', align: 'left' },
        { label: '客户名称', width: 200, prop: 'customerName', align: 'left' },
        { label: '扣款金额', width: 120, prop: 'amount', align: 'center' },
        { label: '描述', width: 260, prop: 'remark', align: 'center' },
        { label: '创建人', width: 80, prop: 'createUserName', align: 'center' },
        { label: '创建时间', width: 100, prop: 'createTime', align: 'center' }
      ],
      btnList: [
        // { name: '删除', type: 'primary', icon: 'edit', click: 'delete', auth: 'deduction_delete', ctr: true, confirm: true }
      ],
      queryList: [
        { name: '加工单号', type: 'text', prop: 'businessCode', placeholder: "加工单号" },
        { name: '订单编号', type: 'query', prop: 'orderNo', rowValue: 'orderNo', rowName: 'orderNo', url: url.ORDER_LIST_URL, columns: colunms().orderColumns, pagination: true, queryList: queryField().order, queryEntity: { status: 1 }, autoInput: true },
        { name: '创建时间', type: 'date', prop: 'startTime', placeholder: "" },
        { name: '----', type: 'date', prop: 'endTime', placeholder: "", },
      ]
    }
  },
  created () {
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {

    doQuery (text) {
      this.$refs['mainGrid'].doQuery(text)
    },
    rowCilck (row) {
      this.disabled = row.length == 0
    },
    doDelete () {
      const row = this.$refs['mainGrid'].getSelectOne()
      if (row) {
        this.deleteOp(row.deductionCode).then(data => {
          if (data) {
            this.$refs['mainGrid'].reload()
          }
        })
      }
    },
    deleteOp (deductionCode) {
      return request({
        url: url.DUDECTION_DELETE_URL,
        method: 'post',
        data: { key: 'key' },
        params: { deductionCode: deductionCode }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.w-body {
  padding-top: 8px;
}
.w-table {
  border: 1px solid #ebeef5;
}
.w-table-title {
  border: 1px solid #ebeef5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  display: inline-block;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  vertical-align: middle;
  width: 100%;
  font-size: 14px;
  color: gray;
}
</style>
